<!DOCTYPE html>
<html>
  <head>
    <title>收货地址管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
	<meta charset="utf-8">
    <!-- Bootstrap -->
    <link rel="stylesheet" href="__PUBLIC__/addon/malltemplatehome/CSS/bootstrap.min.css">
    <link rel="stylesheet" href="__PUBLIC__/addon/malltemplatehome/CSS/reset.css">
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="__PUBLIC__/addon/malltemplatehome/js/jquery-1.11.3.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="__PUBLIC__/addon/malltemplatehome/js/bootstrap.js"></script>
	<!--自己的css样式-->
	<link rel="stylesheet" href="__PUBLIC__/addon/malltemplatehome/CSS/store.css">
	<script src="http://crm.isdce.com/Public/CRM/Admin/ui/area.js"></script>

		<script type="text/javascript">
			var Gid  = document.getElementById ;
			var showArea = function(){
				Gid('show').innerHTML = "<h3>" + Gid('s_province').value + " - " + 
										Gid('s_city').value + " - " + 
										Gid('s_county').value + "</h3>"
			}
			Gid('s_county').setAttribute('onchange','showArea()');
		</script>
		
		<script type="text/javascript">
	//获取共享地址
	function editAddress()
	{
		WeixinJSBridge.invoke(
			'editAddress',
			<?php echo $parameters; ?>,
			function(res){
				var name = res.userName;
				var value1 = res.proviceFirstStageName;
				var value2 = res.addressCitySecondStageName;
				var value3 = res.addressCountiesThirdStageName;
				var value4 = res.addressDetailInfo;
				var tel = res.telNumber;
				
				if(tel){
					
					$.ajax({
							type:'POST',
							url:"__APP__/Home/Address/Create/Addon/Mall.html",
							data:{
								"tel":tel,
								"name":name,
								"province":value1,
								"city":value2,
								"county":value3,
								"address":value4,
								
							},
							success:function(data){			
								var info = eval(data)
								if (info.errcode == 0) {
								
									layer.msg(info.errmsg);
									//setTimeout(window.location.reload(),3000);
									setTimeout(window.location.href="__APP__/{$return_url}",3000);
												
								}else{
									layer.msg(info.errmsg);
								}
							},
							
						
						});
				}
				
				
				
			}
		);
	}
	
	function getWeiXinAddress(){
		if (typeof WeixinJSBridge == "undefined"){
		    if( document.addEventListener ){
		        document.addEventListener('WeixinJSBridgeReady', editAddress, false);
		    }else if (document.attachEvent){
		        document.attachEvent('WeixinJSBridgeReady', editAddress); 
		        document.attachEvent('onWeixinJSBridgeReady', editAddress);
		    }
		}else{
			editAddress();
		}
	};
	
	</script>	
	
  </head>
  <body>
	<!--nav部分开始-->
	<header id="header">
		<div class="row shopping">
			<a href="__APP__/{$top_url}">
			<div class="col-xs-2 col-sm-2">
				<img src="__PUBLIC__/addon/malltemplatehome/images/icon58.jpg">
			</div>
			</a>
			<div class="col-xs-8 col-sm-8">
				收货地址
			</div>
			<div class="col-xs-2 col-sm-2">
			</div>
		</div>
	</header>
	<!--原有收货地址-->
	<div id="default">
		<div class="row text-left">
		    <span  class="addr-new" style="width:45%" data-toggle='modal' data-target='#addr'>
			    新增收货地址</span>
			  <span class="addr-new text-right" style="width:50%" onclick="getWeiXinAddress()" style='display:inlink-block;'>
			    添加微信收货地址</span>
		    </div>
		<volist name="address" id="address">
		<div class="row address-moren">
		    <div class="col-xs-12 col-sm-12">
		       <div class="radio">
                  <label>
                    <input type="radio"  name="address_id" value="{$address.id}" id="address_id">
                   <p>{$address.name}{$address.tel}
    				<if condition="$address.sort eq 1"> 
    				<a  class="btn btn-primary btn-xs">默认</a>
    				
    				<else /> 
    				
    				</if>
    				</p>
    				<p>{$address.province}{$address.city}{$address.county}{$address.address}</p>
                  </label>
                </div>
             </div>

			
		</div>
		</volist>
		
		<div class="row text-right">
			<button type="button" onclick="addressdelete()"  class="btn btn-danger" style="width:50%">删除地址</button>
			
			
		</div>
	</div>
	<!--content模拟框-->
	<div id="addr" class='modal fade' tabindex="='-1' role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="row">
			<input type="text" placeholder="收货人姓名必填" id="name" name="name" class="form-control">
		</div>
		<div class="row">
			<input type="text" placeholder="手机号码必填" id="tel" name="tel" class="form-control">
		</div>
		<div class="row">
			<div class="col-xs-4 col-sm-4">
				<select id="s_province" name="province" class='form-control'>
					
				</select>
			</div>
			<div class="col-xs-4 col-sm-4" class='form-control'>
				<select id="s_city" name="city" class='form-control'>
					
				</select>
			</div>
			<div class="col-xs-4 col-sm-4">
				<select  id="s_county" name="county" class='form-control'>
					
				</select>
			</div>
			<script type="text/javascript">_init_area();</script>
		</div>
		<div class="row">
			<textarea name='address' id="address" placeholder="填写详细地址" class='form-control' rows='3'></textarea>
		</div>
		<div class="row text-center">
			<button type="button" onclick="addresscreate()" class="btn btn-success" style="width:80%;" onclick="addressdefault()">确认</button>
		</div>
	</div>
	<!--footer-->
	<footer class="footer">
		<div class="row">
			<button type="button" onclick="addressdefault()" class="btn btn-success" style="width:100%;">设置为默认收货地址</button>
		</div>
									<script>
										function addressdefault(){  
								
								var address_id = $("input[name='address_id']:checked").val();
							
								$.ajax({
										type:'POST',
										url:"__APP__/Home/Address/Priority/Addon/Mall.html",
										data:{
											"id": address_id,
											
										
										},
										success:function(data){			
											var info = eval(data)
											if (info.errcode == 0) {
											
												layer.msg(info.errmsg);
												setTimeout(window.location.href="__APP__/{$return_url}",3000);
												
											}else{
												layer.msg(info.errmsg);
											}
										},
								
									});	
							
								
								
								 
							} 
							
						function addressdelete(){  
								
								var address_id = $("input[name='address_id']:checked").val();
							
									$.ajax({
										type:'POST',
										url:"__APP__/Home/Address/Delete/Addon/Mall.html",
										data:{
											"id": address_id,
											
										
										},
										success:function(data){			
											var info = eval(data)
											if (info.errcode == 0) {
											
												layer.msg(info.errmsg);
												setTimeout(window.location.reload(),3000);
												
											}else{
												layer.msg(info.errmsg);
											}
										},
								
									});	
							
								
								
								 
							}  
							
							function addresscreate(){  
								var name = $("#name").val();
								var tel = $("#tel").val();
								var address = $("#address").val();
								var province = $("#s_province option:selected").val();
								var city = $("#s_city option:selected").val();
								var county = $("#s_county option:selected").val();
								
								
									$.ajax({
										type:'POST',
										url:"__APP__/Home/Address/Create/Addon/Mall.html",
										data:{
											"name": name,
											"tel": tel,
											"address": address,
											"province": province,
											"city": city,
											"county": county,
										
										},
										success:function(data){			
											var info = eval(data)
											if (info.errcode == 0) {
											
												layer.msg(info.errmsg);
												//setTimeout(window.location.reload(),3000);
												setTimeout(window.location.href="__APP__/{$return_url}",3000);
												
											}else{
												layer.msg(info.errmsg);
											}
										},
								
									});	
							
								
								
								 
							}  
			</script>
	</footer>
<script src="http://static.hongdayun.com/public/layer/2.2/layer.js"></script>
	<script src="http://static.hongdayun.com/public/layDate/1.1/laydate.js"></script>
	<script>
					
				//发送当前页面信息
				function notice(msg){  
					layer.msg(msg);
				}	
						
						
		</script>
		<script>
					
				$(function(){
				    $('.address-moren .col-xs-11').bind('click',function(){
				        $(this).siblings().children('input').attr('checked',true)
				    })
				})	
						
						
		</script>
  </body>
</html>